package com.arofoxmsn.model.message;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import com.arofoxmsn.model.User;

@Entity
public class Message {
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "id", unique = true, nullable = false)
	private long id;
	
	private String subject;
	
	private String message;
	
	@OneToOne
    @NotFound(action=NotFoundAction.IGNORE)
	private Message parentMessage;
	
	@OneToOne
	private User userFrom;
	@OneToOne
	private User userTo;
	
	private Calendar createdAt;
	
	public enum StateType{SENT};
	
	public Message(){}
	
	public Message(String message, User userFrom){
		this.message = message;
		this.userFrom = userFrom;
		this.createdAt = Calendar.getInstance();
		this.state = MessageStateType.SEND;
	}
	
	@Column(name="message_state") 
	@Enumerated(EnumType.ORDINAL) 
	private MessageStateType state;
	
	public long getId() {return id;}
	public void setId(long id) {this.id = id;}
	
	public String getSubject() {return subject;}
	public void setSubject(String subject) {this.subject = subject;}
	
	public String getMessage() {return message;}
	public void setMessage(String message) {this.message = message;}
	
	public Message getParentMessage() {return parentMessage;}
	public void setParentMessage(Message parentMessage) {this.parentMessage = parentMessage;}
	
	public User getUserFrom() {return userFrom;}
	public void setUserFrom(User userFrom) {this.userFrom = userFrom;}
	
	public User getUserTo() {return userTo;}
	public void setUserTo(User userTo) {this.userTo = userTo;}
	
	public Calendar getCreatedAt() {return createdAt;}
	public void setCreatedAt(Calendar createdAt) {this.createdAt = createdAt;}
	
	public MessageStateType getState() {return state;}
	public void setState(MessageStateType state) {this.state = state;}
	
}
